﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace GodofTroll
{
    class Cenario
    {
        private Game1 game1;
        //Variaveis do background
        //Texture2D backgroundPilastra;

        //Variaveis da textura do cenario
        Texture2D teto1, teto2, teto3;
        Texture2D bloco1;
        Texture2D bloco2;
        Texture2D bloco3;
        Texture2D bloco4;
        Texture2D bloco5;
        Texture2D bloco6;
        Texture2D bloco7;
        Texture2D bloco8;
        Texture2D bloco9;
        Texture2D bloco10;
        Texture2D bloco11;
        Texture2D bloco12;
        Texture2D bloco13;

        //Regioes de colisao dos Rectangle do cenario
        // Bloco1 Horizontais
        Rectangle H1B1, H2B1, H3B1;
        Rectangle H1B3, H2B3, H3B3, H4B3;
        Rectangle H1B4, H2B4, H3B4;
        Rectangle H1B5, H2B5, H3B5, H4B5, H5B5, H6B5, H7B5;
        Rectangle H1B6, H2B6, H3B6, H4B6, H5B6, H6B6, H7B6, H8B6;
        Rectangle H1B7, H2B7;
        Rectangle H1B8;
        Rectangle H1B9;
        Rectangle H1B10;
        Rectangle H1B11, H2B11, H3B11, H4B11, H5B11, H6B11;

        // Bloco1 Verticais
        Rectangle V1B1, V2B1, V3B1;
        Rectangle V1B3, V2B3, V3B3;
        Rectangle V1B4, V2B4;
        Rectangle V1B5, V2B5, V3B5, V4B5, V5B5;
        Rectangle V1B6, V2B6, V3B6, V4B6, V5B6, V6B6, V7B6, V8B6;
        Rectangle V1B7, V2B7, V3B7;
        Rectangle V1B8, V2B8;
        Rectangle V1B9, V2B9;
        Rectangle V1B12;
        Rectangle V1B13;

        public Cenario(Game1 game1)
        {
            // TODO: Complete member initialization
            this.game1 = game1;
            iniciar();
        }

        private void iniciar()
        {
            // backgroundPilastra = game1.Content.Load<Texture2D>("Menu\\pilastras com transparencia");
            
            teto1 = game1.Content.Load<Texture2D>("TileSheet\\teto1");
            teto2 = game1.Content.Load<Texture2D>("TileSheet\\teto2");
            teto3 = game1.Content.Load<Texture2D>("TileSheet\\teto3");
            bloco1 = game1.Content.Load<Texture2D>("TileSheet\\bloco1");
            bloco2 = game1.Content.Load<Texture2D>("TileSheet\\bloco2");
            bloco3 = game1.Content.Load<Texture2D>("TileSheet\\bloco3");
            bloco4 = game1.Content.Load<Texture2D>("TileSheet\\bloco4");
            bloco5 = game1.Content.Load<Texture2D>("TileSheet\\bloco5");
            bloco6 = game1.Content.Load<Texture2D>("TileSheet\\bloco6");
            bloco7 = game1.Content.Load<Texture2D>("TileSheet\\bloco7");
            bloco8 = game1.Content.Load<Texture2D>("TileSheet\\bloco8");
            bloco9 = game1.Content.Load<Texture2D>("TileSheet\\bloco9");
            bloco10 = game1.Content.Load<Texture2D>("TileSheet\\bloco10");
            bloco11 = game1.Content.Load<Texture2D>("TileSheet\\bloco11");
            bloco12 = game1.Content.Load<Texture2D>("TileSheet\\bloco12");
            bloco13 = game1.Content.Load <Texture2D>("TileSheet\\bloco13");
        }

        public void posicoesRectangle() // Codificar o limite de tela com colisoes de bordas && Posicao dos Rectangles
        {
            //Areas transparentes postas no chao para colisao
        #region - Blocos Horizontais
            //Bloco1
            H1B1 = new Rectangle(0, 550, 57, 1);
            H2B1 = new Rectangle(58, 588, 62, 1);
            H3B1 = new Rectangle(119, 615, 677, 1);
            //Bloco3
            H1B3 = new Rectangle(795, 649, 94, 1);
            H2B3 = new Rectangle(889, 784, 121, 1);
            H3B3 = new Rectangle(1010, 955, 115, 1);
            H4B3 = new Rectangle(795, 1249, 330, 1);
            //Bloco4
            H1B4 = new Rectangle(1110, 600, 620, 1);
            H2B4 = new Rectangle(1110, 860, 140, 1);
            H3B4 = new Rectangle(1250, 1112, 375, 1);
            //Bloco5
            H1B5 = new Rectangle(1730, 600, 258, 1);
            H2B5 = new Rectangle(1988, 669, 119, 1);
            H3B5 = new Rectangle(2107, 732, 101, 1);
            H4B5 = new Rectangle(2208, 832, 118, 1);
            H5B5 = new Rectangle(2326, 954, 78, 1);
            H6B5 = new Rectangle(2404, 1062, 126, 1);
            H7B5 = new Rectangle(1730, 1200, 800, 1);
            //Bloco6
            H1B6 = new Rectangle(2530,600,100,1);
            H2B6 = new Rectangle(2693,600,107,1);
            H3B6 = new Rectangle(2800,903,59,1);
            H4B6 = new Rectangle(2859,983,39,1);
            H5B6 = new Rectangle(2896,1061,51,1);
            H6B6 = new Rectangle(2949,1137,72,1);
            H7B6 = new Rectangle(2693,1200,328,1);
            H8B6 = new Rectangle(2530,1200,100,1);
            //Bloco7
            H1B7 = new Rectangle(3870, 421, 34, 1);
            H2B7 = new Rectangle(3904, 348, 128, 1);
            //Bloco8
            H1B8 = new Rectangle(3870, 1057, 209, 1);
            //Bloco9
            H1B9 = new Rectangle(0, 1303, 800, 1);
            //Bloco10
            H1B10 = new Rectangle(415, 1794, 800, 1);
            //Bloco11
            H1B11 = new Rectangle(1215, 1794, 800, 1);
            H2B11 = new Rectangle(2015, 1794, 800, 1);
            H3B11 = new Rectangle(2815, 1794, 800, 1);
            H4B11 = new Rectangle(3615, 1794, 600, 1);
            H5B11 = new Rectangle(1050, 1189, 800, 1);
            H6B11 = new Rectangle(1050, 1214, 800, 1);
        #endregion    

        #region Blocos Verticais
            //Bloco1
            V1B1 = new Rectangle(57, 550, 1, 38);
            V2B1 = new Rectangle(119, 588, 1, 27);
            V3B1 = new Rectangle(795, 615, 1, 23);
            //Bloco3
            V1B3 = new Rectangle(889, 649, 1, 134);
            V2B3 = new Rectangle(1010, 783, 1, 171);
            V3B3 = new Rectangle(1125, 954, 1, 295);
            //Bloco4
            V1B4 = new Rectangle(1110, 600, 1, 260);
            V2B4 = new Rectangle(1250, 860, 1, 252);
            //Bloco5
            V1B5 = new Rectangle(1988, 600, 1, 69);
            V2B5 = new Rectangle(2107, 669, 1, 63);
            V3B5 = new Rectangle(2208, 732, 1, 100);
            V4B5 = new Rectangle(2326, 832, 1, 122);
            V5B5 = new Rectangle(2404, 954, 1, 108);
            //Bloco6
            V1B6 = new Rectangle(2530,600,1,600);
            V2B6 = new Rectangle(2630,600,1,600);
            V3B6 = new Rectangle(2693,600,1,600);
            V4B6 = new Rectangle(2800,600,1,303);
            V5B6 = new Rectangle(2859,903,1,80);
            V6B6 = new Rectangle(2898,983,1,78);
            V7B6 = new Rectangle(2949,1061,1,76);
            V8B6 = new Rectangle(3021,1137,1,63);
            //Bloco7
            V1B7 = new Rectangle(3870, 455, 1, 397);
            V2B7 = new Rectangle(3904, 350, 1, 75);
            V3B7 = new Rectangle(4033, 200, 1, 160);
            //Bloco8
            V1B8 = new Rectangle(3870, 852, 1, 305);
            V2B8 = new Rectangle(4079, 1157, 1, 295);
            //Bloco9
            V1B9 = new Rectangle(415, 1303, 1, 527);
            V2B9 = new Rectangle(800, 1230, 1, 73);
            //Bloco12
            V1B12 = new Rectangle(4079, 1452, 1, 460);
            //Bloco13
            V1B13 = new Rectangle(1610, 990, 1, 200);
        #endregion
        }

        public void Mapa(GameTime gameTime, SpriteBatch spriteBatch)
        {
            
            // Separado blocos
            spriteBatch.Draw(bloco1, new Vector2(0, 550), Color.White);
            spriteBatch.Draw(bloco2, new Vector2(0, 630), Color.White);
            spriteBatch.Draw(bloco3, new Vector2(800, 650), Color.White);
            spriteBatch.Draw(bloco4, new Vector2(830, 600), Color.White);
            spriteBatch.Draw(bloco5, new Vector2(1730, 600), Color.White);
            spriteBatch.Draw(bloco6, new Vector2(2530, 600), Color.White);
            spriteBatch.Draw(bloco7, new Vector2(3320, 220), Color.White);
            spriteBatch.Draw(bloco8, new Vector2(3320, 820), Color.White);
            spriteBatch.Draw(bloco9, new Vector2(0, 1230), Color.White);
            spriteBatch.Draw(bloco10, new Vector2(400, 1230), Color.White);
            spriteBatch.Draw(bloco11, new Vector2(1200, 1230), Color.White);
            spriteBatch.Draw(bloco11, new Vector2(2000, 1230), Color.White);
            spriteBatch.Draw(bloco11, new Vector2(2000, 1230), Color.White);
            spriteBatch.Draw(bloco11, new Vector2(2800, 1230), Color.White);
            spriteBatch.Draw(bloco11, new Vector2(1100, 620), Color.White);
            spriteBatch.Draw(bloco11, new Vector2(3287, 1230), Color.White);
            spriteBatch.Draw(bloco12, new Vector2(3909, 1372), Color.White);
            spriteBatch.Draw(bloco13, new Vector2(1600, 1000), Color.White);

            // Separado Tetos
            spriteBatch.Draw(teto1, new Vector2(0, 0), Color.White);
            spriteBatch.Draw(teto2, new Vector2(800, 0), Color.White);
            spriteBatch.Draw(teto3, new Vector2(2523, 0), Color.White);

            //background
          //  spriteBatch.Draw(backgroundPilastra, Vector2.Zero, new Rectangle(0, 0, (game1.graphics.PreferredBackBufferWidth *2 ), game1.graphics.PreferredBackBufferHeight), Color.White);

        }
         
        public void Colisao()
        {
          #region Colisoes horizontais  :: EIXO Y
            //Bloco1
                if (game1.personRectangle.Intersects(this.H1B1))
                {
                    game1.pular = true;
                    game1.velocidadeQueda = 0;
                    game1.personRectangle.Y = this.H1B1.Y - game1.personRectangle.Height; 
                }
                if (game1.personRectangle.Intersects(this.H2B1))
                {
                    game1.pular = true;
                    game1.velocidadeQueda = 0; 
                    game1.personRectangle.Y = this.H2B1.Y - game1.personRectangle.Height;
                }
                if (game1.personRectangle.Intersects(this.H3B1))
                {
                    game1.pular = true;
                    game1.velocidadeQueda = 0;
                    game1.personRectangle.Y = this.H3B1.Y - game1.personRectangle.Height;
                
                }
                        //Bloco3
                            if (game1.personRectangle.Intersects(this.H1B3))
                            {
                                game1.pular = true;
                                game1.velocidadeQueda = 0; 
                                game1.personRectangle.Y = this.H1B3.Y - game1.personRectangle.Height;
                            }
                            if (game1.personRectangle.Intersects(this.H2B3))
                            {
                                game1.pular = true;
                                game1.velocidadeQueda = 0; 
                                game1.personRectangle.Y = this.H2B3.Y - game1.personRectangle.Height;
                            }
                            if (game1.personRectangle.Intersects(this.H3B3))
                            {
                                game1.pular = true;
                                game1.velocidadeQueda = 0; 
                                game1.personRectangle.Y = this.H3B3.Y - game1.personRectangle.Height;
                            }
                            if (game1.personRectangle.Intersects(this.H4B3))
                            {
                                game1.pular = true;
                                game1.velocidadeQueda = 0; 
                                game1.personRectangle.Y = this.H4B3.Y;
                            }
            //Bloco4
                if (game1.personRectangle.Intersects(this.H1B4))
                {
                    game1.pular = true;
                    game1.velocidadeQueda = 0; 
                    game1.personRectangle.Y = this.H1B4.Y - game1.personRectangle.Height;
                }
                if (game1.personRectangle.Intersects(this.H2B4))
                {
                    game1.pular = true;
                    game1.velocidadeQueda = 0; 
                    game1.personRectangle.Y = this.H2B4.Y;
                }
                if (game1.personRectangle.Intersects(this.H3B4))
                {
                    game1.pular = true;
                    game1.velocidadeQueda = 0; 
                    game1.personRectangle.Y = this.H3B4.Y;
                }
                        //Bloco5
                            if (game1.personRectangle.Intersects(this.H1B5))
                            {
                                game1.pular = true;
                                game1.velocidadeQueda = 0; 
                                game1.personRectangle.Y = this.H1B5.Y - game1.personRectangle.Height;
                            }
                            if (game1.personRectangle.Intersects(this.H2B5))
                            {
                                game1.pular = true;
                                game1.velocidadeQueda = 0; 
                                game1.personRectangle.Y = this.H2B5.Y - game1.personRectangle.Height;
                            }
                            if (game1.personRectangle.Intersects(this.H3B5))
                            {
                                game1.pular = true;
                                game1.velocidadeQueda = 0; 
                                game1.personRectangle.Y = this.H3B5.Y - game1.personRectangle.Height;
                            }
                            if (game1.personRectangle.Intersects(this.H4B5))
                            {
                                game1.pular = true;
                                game1.velocidadeQueda = 0; 
                                game1.personRectangle.Y = this.H4B5.Y - game1.personRectangle.Height;
                            }
                            if (game1.personRectangle.Intersects(this.H5B5))
                            {
                                game1.pular = true;
                                game1.velocidadeQueda = 0; 
                                game1.personRectangle.Y = this.H5B5.Y - game1.personRectangle.Height;
                            }
                            if (game1.personRectangle.Intersects(this.H6B5))
                            {
                                game1.pular = true;
                                game1.velocidadeQueda = 0; 
                                game1.personRectangle.Y = this.H6B5.Y - game1.personRectangle.Height;
                            }
                            if (game1.personRectangle.Intersects(this.H7B5))
                            {
                                game1.pular = true;
                                game1.velocidadeQueda = 0; 
                                game1.personRectangle.Y = this.H7B5.Y;
                            } 
            //Bloco6
        if (game1.personRectangle.Intersects(this.H1B6))
        {
            game1.pular = true;
            game1.velocidadeQueda = 0; 
            game1.personRectangle.Y = this.H1B6.Y - game1.personRectangle.Height;
        }
        if (game1.personRectangle.Intersects(this.H2B6))
        {
            game1.pular = true;
            game1.velocidadeQueda = 0; 
            game1.personRectangle.Y = this.H2B6.Y - game1.personRectangle.Height;
        } 
        if (game1.personRectangle.Intersects(this.H3B6))
        {
            game1.pular = true;
            game1.velocidadeQueda = 0; 
            game1.personRectangle.Y = this.H3B6.Y - game1.personRectangle.Height;
        } 
        if (game1.personRectangle.Intersects(this.H4B6))
        {
            game1.pular = true;
            game1.velocidadeQueda = 0; 
            game1.personRectangle.Y = this.H4B6.Y - game1.personRectangle.Height;
        } 
        if (game1.personRectangle.Intersects(this.H5B6))
        {
            game1.pular = true;
            game1.velocidadeQueda = 0; 
            game1.personRectangle.Y = this.H5B6.Y - game1.personRectangle.Height;
        } 
        if (game1.personRectangle.Intersects(this.H6B6))
        {
            game1.pular = true;
            game1.velocidadeQueda = 0; 
            game1.personRectangle.Y = this.H6B6.Y - game1.personRectangle.Height;
        } 
        if (game1.personRectangle.Intersects(this.H7B6))
        {
            game1.pular = true;
            game1.velocidadeQueda = 0; 
            game1.personRectangle.Y = this.H7B6.Y;
        } 
        if (game1.personRectangle.Intersects(this.H8B6))
        {
            game1.pular = true;
            game1.velocidadeQueda = 0; 
            game1.personRectangle.Y = this.H8B6.Y;
        }
                        //Bloco7
                            if (game1.personRectangle.Intersects(this.H1B7))
                            {
                                game1.pular = true;
                                game1.velocidadeQueda = 0; 
                                game1.personRectangle.Y = this.H1B7.Y - game1.personRectangle.Height;
                            }
                            if (game1.personRectangle.Intersects(this.H2B7))
                            {
                                game1.pular = true;
                                game1.velocidadeQueda = 0; 
                                game1.personRectangle.Y = this.H2B7.Y - game1.personRectangle.Height;
                            }
            //Bloco8
        if (game1.personRectangle.Intersects(this.H1B8))
        {
            game1.pular = true;
            game1.velocidadeQueda = 0; 
            game1.personRectangle.Y = this.H1B8.Y;
        }
                        //Bloco9
                            if (game1.personRectangle.Intersects(this.H1B9))
                            {
                                game1.pular = true;
                                game1.velocidadeQueda = 0; 
                                game1.personRectangle.Y = this.H1B9.Y;
                            }
            //Bloco10
        if (game1.personRectangle.Intersects(this.H1B10))
        {
            game1.pular = true;
            game1.velocidadeQueda = 0; 
            game1.personRectangle.Y = this.H1B10.Y - game1.personRectangle.Height;
        }
            //Bloco11
        if (game1.personRectangle.Intersects(this.H1B11))
        {
            game1.pular = true;
            game1.velocidadeQueda = 0; 
            game1.personRectangle.Y = this.H1B11.Y - game1.personRectangle.Height;
        }
        if (game1.personRectangle.Intersects(this.H2B11))
        {
            game1.pular = true;
            game1.velocidadeQueda = 0; 
            game1.personRectangle.Y = this.H2B11.Y - game1.personRectangle.Height;
        }
        if (game1.personRectangle.Intersects(this.H3B11))
        {
            game1.pular = true;
            game1.velocidadeQueda = 0; 
            game1.personRectangle.Y = this.H3B11.Y - game1.personRectangle.Height;
        }
        if (game1.personRectangle.Intersects(this.H4B11))
        {
            game1.pular = true;
            game1.velocidadeQueda = 0; 
            game1.personRectangle.Y = this.H4B11.Y - game1.personRectangle.Height;
        }
        if (game1.personRectangle.Intersects(this.H5B11))
        {
            game1.pular = true;
            game1.velocidadeQueda = 0; 
            game1.personRectangle.Y = this.H5B11.Y - game1.personRectangle.Height;
        }
        if (game1.personRectangle.Intersects(this.H6B11))
        {
            game1.pular = true;
            game1.velocidadeQueda = 0; 
            game1.personRectangle.Y = this.H6B11.Y;
        }
        #endregion


          #region Colisoes verticais :: EIXO X
        //Bloco1
                if (game1.personRectangle.Intersects(this.V1B1))
                { game1.personRectangle.X = this.V1B1.X; }
                if (game1.personRectangle.Intersects(this.V2B1))
                { game1.personRectangle.X = this.V2B1.X; }
                if (game1.personRectangle.Intersects(this.V3B1))
                { game1.personRectangle.X = this.V3B1.X; }
                        //Bloco3
                            if (game1.personRectangle.Intersects(this.V1B3))
                            { game1.personRectangle.X = this.V1B3.X; }
                            if (game1.personRectangle.Intersects(this.V2B3))
                            { game1.personRectangle.X = this.V2B3.X; }
                            if (game1.personRectangle.Intersects(this.V3B3))
                            { game1.personRectangle.X = this.V3B3.X; }
            //Bloco4
                if (game1.personRectangle.Intersects(this.V1B4))
                { game1.personRectangle.X = this.V1B4.X - game1.personRectangle.Width; }
                if (game1.personRectangle.Intersects(this.V2B4))
                { game1.personRectangle.X = this.V2B4.X - game1.personRectangle.Width; }
                        //Bloco5
                            if (game1.personRectangle.Intersects(this.V1B5))
                            { game1.personRectangle.X = this.V1B5.X; }
                            if (game1.personRectangle.Intersects(this.V2B5))
                            { game1.personRectangle.X = this.V2B5.X; }
                            if (game1.personRectangle.Intersects(this.V3B5))
                            { game1.personRectangle.X = this.V3B5.X; }
                            if (game1.personRectangle.Intersects(this.V4B5))
                            { game1.personRectangle.X = this.V4B5.X; }
                            if (game1.personRectangle.Intersects(V5B5))
                            { game1.personRectangle.X = this.V5B5.X; }
            //Bloco6
            if (game1.personRectangle.Intersects(this.V1B6))
            { game1.personRectangle.X = this.V1B6.X - game1.personRectangle.Width; }
            if (game1.personRectangle.Intersects(this.V2B6))
            { game1.personRectangle.X = this.V2B6.X; }
            if (game1.personRectangle.Intersects(this.V3B6))
            { game1.personRectangle.X = this.V3B6.X - game1.personRectangle.Width; }
            if (game1.personRectangle.Intersects(this.V4B6))
            { game1.personRectangle.X = this.V4B6.X; }
            if (game1.personRectangle.Intersects(this.V5B6))
            { game1.personRectangle.X = this.V5B6.X; }
            if (game1.personRectangle.Intersects(this.V6B6))
            { game1.personRectangle.X = this.V6B6.X; }
            if (game1.personRectangle.Intersects(this.V7B6))
            { game1.personRectangle.X = this.V7B6.X; }
            if (game1.personRectangle.Intersects(this.V8B6))
            { game1.personRectangle.X = this.V8B6.X; }
                            //Bloco7
                            if (game1.personRectangle.Intersects(this.V1B7))
                            { game1.personRectangle.X = this.V1B7.X - game1.personRectangle.Width; }
                            if (game1.personRectangle.Intersects(this.V2B7))
                            { game1.personRectangle.X = this.V2B7.X - game1.personRectangle.Width; }
                            if (game1.personRectangle.Intersects(this.V3B7))
                            { game1.personRectangle.X = this.V3B7.X - game1.personRectangle.Width; }
            //Block8
            if (game1.personRectangle.Intersects(V1B8))
            { game1.personRectangle.X = this.V1B8.X - game1.personRectangle.Width; }
            if (game1.personRectangle.Intersects(this.V2B8))
            { game1.personRectangle.X = this.V2B8.X - game1.personRectangle.Width;}
                            //Bloco9
                                if (game1.personRectangle.Intersects(this.V1B9))
                                { game1.personRectangle.X = this.V1B9.X; }
                                if (game1.personRectangle.Intersects(V2B9))
                                { game1.personRectangle.X = this.V2B9.X; }
            //Bloco12
            if (game1.personRectangle.Intersects(V1B12))
            { game1.personRectangle.X = this.V1B12.X - game1.personRectangle.Width; }
            //Bloco13
            if (game1.personRectangle.Intersects(V1B13))
            { game1.personRectangle.X = this.V1B13.X - game1.personRectangle.Width; }
            #endregion
        }
    }
}           